package Ioperation;

import book.BookList;

import java.util.Scanner;

public class Findoperation implements Ioperation{
    @Override
    public void work(BookList books) {
        Scanner scanner = new Scanner(System.in);
        int ret = books.getBooksSize();
        if(ret == 0){
            System.out.println("书架上没有书!");
            return;
        }

        System.out.println("请输入要查找的书名:");
        //遍历进行查找 如果有就打印书的信息
        //因为书架上的书是由 private 所修饰的
        //所以不能 books[i] 这样取出，只能 getBooks
        String name = scanner.nextLine();
        for (int i = 0; i < ret; i++) {
            if(name.equals(books.getBooks(i).getName())){
                System.out.println(books.getBooks(i));
                return;
            }
        }
        System.out.println("没有这本书!");
    }
}
